//
//  CalenderLabel.m
//  CalenderDemo
//
//  Created by wr on 2018/7/23.
//  Copyright © 2018年 stzen. All rights reserved.
//

#import "CalenderLabel.h"
#import "UIView+Frame.h"

#define kBorderWith 1

@implementation CalenderLabel

- (void)drawRect:(CGRect)rect {
    if (self.isCurrentDay) {
        CGContextRef ctx = UIGraphicsGetCurrentContext();
        CGRect bigRect = CGRectMake(rect.origin.x + kBorderWith,
                                    rect.origin.y+ kBorderWith,
                                    rect.size.width - kBorderWith * 2,
                                    rect.size.height - kBorderWith * 2);

        CGContextSetLineWidth(ctx, kBorderWith);
        CGContextAddEllipseInRect(ctx, bigRect);
        [[UIColor greenColor] set];
        CGContextStrokePath(ctx);
    }
    
    if (self.isSelected) {
        [[UIColor redColor] setFill];
        UIBezierPath *path = [UIBezierPath bezierPath];
        [path addArcWithCenter:CGPointMake(self.width / 2, self.height / 2) radius:self.height / 2 startAngle:0.0 endAngle:180.0 clockwise:YES];
        [path fill];
    }
    [super drawRect:rect];
}

#pragma mark - Setter

- (void)setIsSelected:(BOOL)isSelected {
    _isSelected = isSelected;
    [self setNeedsDisplay];
}

- (void)setIsCurrentDay:(BOOL)isCurrentDay {
    _isCurrentDay = isCurrentDay;
    [self setNeedsDisplay];
}

@end
